package cn.npe.dynamic.thread.pool.sdk.config.postprocessor;

import cn.npe.dynamic.thread.pool.sdk.domain.model.entity.DtpThreadPoolExecutor;
import cn.npe.dynamic.thread.pool.sdk.registry.DtpContext;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;

import java.util.concurrent.ThreadPoolExecutor;
/**
 * @ClassName DtpBeanPostProcessor
 * @Author zhjx
 * @Description  初始化后将所有线程池放入DtpContext的缓存 统一维护
 * @Date 2024/5/23 14:51
 **/
public class DtpBeanPostProcessor implements BeanPostProcessor {

    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        if (bean instanceof DtpThreadPoolExecutor) {
            //直接纳入管理
            DtpContext.add(beanName, (ThreadPoolExecutor) bean);
        }
        return bean;
    }
}